module V1
  class AdSources < Grape::API
    # status 10-删除 1-导入 2-新建
    # ad_source_type video image
    get 'ad_source/list' do
      sql_p = {}
      sql_p[:ad_source_name] = params[:ad_source_name] if params[:ad_source_name].present?
      ad_source = AdSource.where.not(status:10).where(sql_p)
      render_json list:ad_source.page(params[:page]).per(params[:per]), count:ad_source.count
    end

    post 'ad_source/create' do
      params[:status] = 2
      render_json AdSource.create(params)
    end

    post 'ad_source/delete' do
      AdSource.find_by(id:params[:id]).update(status:10)
      render_json
    end

    post 'ad_source/update' do
      AdSource.find_by(id:params[:id]).update(params)
      render_json
    end
  end
end

